#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define endl '\n'
const size_t maxn = 1000 + 50;
ll dp[maxn][maxn];
ll a[maxn + 1];

ll f(int left, int right) {
    if (dp[left][right] != 0)return dp[left][right];
    if (left == right) return 0;
    if (left + 1 == right) return dp[left][right] = a[left] * a[left + 1] * a[right + 1];
    ll best = INT_MAX / 8;
    for (int i = left; i <= right - 1; i++) {
        ll fl = f(left, i);       // m[left]*m[left+1]...*m[i]
        ll fr = f(i + 1, right);  // m[i+1]*....m[right]

        best = min(best, fl + fr + a[left] * a[i + 1] * a[right + 1]);
    }
    return dp[left][right] = best;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> a[i + 1];
    }
    cout << f(0, n - 1) << endl;

    return 0;
}
